<template>
	<view class="page-body">
		<!-- 页面内容开始 -->

		<view class="" style="display: flex;justify-content: left;align-items: top;">
			
			<view class="" style="margin-right: 10px;">
				<!-- 批量操作 -->
				<el-button type="danger" size="medium" 	@click="deletesBtn" :disabled="table1.multipleSelection.length === 0" >
					批量删除
				</el-button>
			</view>
			
			<!-- 表格搜索组件开始 -->
			<vk-data-table-query
				v-model="queryForm1.formData"
				:columns="queryForm1.columns"
				:show-reset="true"
				@search="search"
			></vk-data-table-query>
			<!-- 表格搜索组件结束 -->
		</view>
		
		<!-- 表格组件开始 -->
		<vk-data-table
			ref="table1"
			:action="table1.action"
			:columns="table1.columns"
			:query-form-param="queryForm1"
			:right-btns="['detail_auto', 'delete']"
			:selection="true"
			:row-no="false"
			:pagination="true"
			@delete="deleteBtn"
			@current-change="currentChange"
			@selection-change="selectionChange"
		></vk-data-table>
		<!-- 表格组件结束 -->
		<!-- 页面内容结束 -->
	</view>
</template>

<script>
	var that;													// 当前页面对象
	var vk = uni.vk;									// vk实例
	var originalForms = {};						// 表单初始化数据

	var postionData = [
		{ value:0, label:"壁纸", tagType:"default" },
		{ value:1, label:"头像", tagType:"warning" },
		{ value:2, label:"视频", tagType:"success" },
		{ value:3, label:"刘海", tagType:"info" },
		{ value:4, label:"挂件", tagType:"info" },
		{ value:5, label:"表情包", tagType:"warning" }
	];
	
	var modeData = [
		{ value: 'wx_ad', label:"微信广告", size: "mini" },
		{ value: 'qq_ad', label:"QQ广告", size: "mini" },
		{ value: 'tt_ad', label:"抖音广告", size: "mini" },
		{ value: 'ks_ad', label:"快手广告", size: "mini" },
		{ value: 'free', label:"免费下载", size: "mini" },
		{ value: 'score', label:"积分下载", size: "mini" },
	];
	
	var originData = [
		{ value: 'wx', label:"微信", tagType:"success", size: "mini" },
		{ value: 'qq', label:"QQ", tagType:"warning", size: "mini" },
		{ value: 'tt', label:"抖音", tagType:"primary", size: "mini" },
		{ value: 'ks', label:"快手", tagType:"danger", size: "mini" },
	];
	export default {
		data() {
			// 页面数据变量
			return {
				// 页面是否请求中或加载中
				loading:false,
				// init请求返回的数据
				data:{

				},
				// 表格相关开始 -----------------------------------------------------------
				table1:{
					// 表格数据请求地址
					action:"admin/wechat/order/sys/getList",
					// 表格字段显示规则
					columns: [
						{ key:"user.avatar", title:"用户头像", type:"avatar" },
						{ key:"user.nickname", title:"用户昵称", type:"text" },
						{ key:"mode", title:"类型", type:"tag",
							data: postionData
						},
						{ key:"image", title:"缩略图", type:"image" },
						{ key:"score", title:"积分", type:"text" },
						{ key:"author.nickname", title:"作者", type:"text" },
						{ key:"origin", title:"下载方式", type:"text" },
						// { key:"video", title:"缩略图", showRule:"mode=2", type:"html",
						// 	formatter: function(val, row, column, index) {
						// 		return '<image style="width: 80px;height:80px;" src="'+val+'?x-oss-process=video/snapshot,t_1000,m_fast'+'">'
						//     }
						// },
						{ key:"comment", title:"订单说明", type:"text" },
						{ key:"user.origin", title:"客户端", type:"text", type:"tag",
							data: originData
						},
						{ key:"_add_time", title:"订单时间", type:"time", width:160 },
					],
					// 多选框选中的值
					multipleSelection:[],
					// 当前高亮的记录
					selectItem:"",
				},
				// 表格相关结束 -----------------------------------------------------------
				// 表单相关开始-----------------------------------------------------------
				// 查询表单请求数据
				queryForm1:{
					// 查询表单数据源，可在此设置默认值
					formData:{
						
					},
					// 查询表单的字段规则 fieldName:指定数据库字段名,不填默认等于key
					columns:[
						{ key:"user._id", placeholder:"用户ID", type:"text", width: 160, mode:"%%", lastWhereJson: true  },
						{ key:"user.nickname", placeholder:"用户昵称", type:"text", width: 160, mode:"%%", lastWhereJson: true  },
						{ key:"user.origin", placeholder:"客户端", width: 160, mode:"%%", lastWhereJson: true , type:"select",
							data: originData
						},
						{ key:"origin", placeholder:"下载方式", type:"select", width: 160,
							data: modeData
						},
						{ key:"mode", placeholder:"所有类型", type:"select", width:160,
							data: postionData
						}
					]
				},
				// 其他表单属性容器(请勿修改)
				formDatas:{},
				// 表单相关结束-----------------------------------------------------------
			};
		},
		// 监听 - 页面每次【加载时】执行(如：前进)
		onLoad(options = {}) {
			that = this;
			vk = that.vk;
			that.options = options;
			that.init(options);
		},
		// 监听 - 页面【首次渲染完成时】执行。注意如果渲染速度快，会在页面进入动画完成前触发
		onReady() {},
		// 监听 - 页面每次【显示时】执行(如：前进和返回) (页面每次出现在屏幕上都触发，包括从下级页面点返回露出当前页面)
		onShow() {},
		// 监听 - 页面每次【隐藏时】执行(如：返回)
		onHide() {},
		// 函数
		methods: {
			// 页面数据初始化函数
			init(options) {
				originalForms["form1"] = vk.pubfn.copyObject(that.form1);
			},
			deletesBtn(){
				that.$confirm('确定要批量删除吗？').then(async _ => {
					that.$refs.table1.refresh()
					let _ids = [];
					that.table1.multipleSelection.map((item,index)=>{
						_ids.push(item._id);
					});
					let data = await vk.callFunction({
						url: '/admin/wechat/index/sys/deletes',
						data: {
							dbName: 'bus-wx-order',
							_ids: _ids
						}
					});
				}).catch(_ => {});
			},
			// 页面跳转
			pageTo(path) {
				vk.navigateTo(path);
			},
			// 表单重置
			resetForm(){
				vk.pubfn.resetForm(originalForms, that);
			},
			// 搜索
			search(){
				that.$refs.table1.query();
			},
			// 刷新
			refresh(){
				that.$refs.table1.refresh();
			},
			// 获取当前选中的行的数据
			getCurrentRow(){
				return that.$refs.table1.getCurrentRow();
			},
			// 监听 - 行的选中高亮事件
			currentChange(val){
				that.table1.selectItem = val;
			},
			// 当选择项发生变化时会触发该事件
			selectionChange(list) {
				that.table1.multipleSelection = list;
			},
			// 删除按钮
			deleteBtn({ item, deleteFn }){
				deleteFn({
					action:"admin/wechat/order/sys/delete",
					data:{
						_id: item._id
					},
				});
			},
			// 权限赋予按钮
			bindPermissionBtn(){
				let item = that.getCurrentRow();
				that.formDatas.bindPermission = {
					show:true,
					item:item,
				};
			},
		  // 菜单赋予绑定按钮
			bindMenu(){
				let item = that.getCurrentRow();
				that.formDatas.bindMenu = {
					show:true,
					item:item,
				};
			}
		},
		// 监听属性
		watch: {

		},
		// 过滤器
		filters: {

		},
		// 计算属性
		computed: {

		}
	};
</script>
<style lang="scss" scoped>
	/deep/ .el-tree-node__content .el-checkbox {
		margin-right: 8px;
	}
</style>